// image_decoder.hpp
#ifndef IMAGE_DECODER_HPP
#define IMAGE_DECODER_HPP

#include <turbojpeg.h>  // 使用TurboJPEG头文件
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>

// 解码器上下文
typedef struct {
    tjhandle handle;                // TurboJPEG解压缩句柄
    unsigned char* output_buffer;   // 预分配的RGB888缓冲区
    size_t buffer_size;             // 缓冲区大小
} MJpegDecoder;

#ifdef __cplusplus
extern "C" {
#endif

MJpegDecoder* mjpeg_decoder_init(uint32_t width, uint32_t height);
int mjpeg_decoder_process(MJpegDecoder* decoder, const unsigned char* mjpeg_data, 
                          size_t data_size, uint32_t width, uint32_t height, 
                          unsigned char ** out_rgb);
void mjpeg_decoder_release(MJpegDecoder* decoder);

#ifdef __cplusplus
}
#endif

#endif // IMAGE_DECODER_HPP